@echo off
chcp 65001 > nul
REM ========================================================================
REM JAR更新工具 - 简化版Windows EXE打包脚本
REM 快速打包，最少交互
REM ========================================================================

echo.
echo ═══════════════════════════════════════════════
echo   JAR更新工具 - 快速打包
echo ═══════════════════════════════════════════════
echo.

REM 进入项目根目录（如果从scripts目录运行）
if exist "..\src\main.py" (
    cd ..
)

REM 检查环境
python --version >nul 2>&1
if errorlevel 1 (
    echo [错误] Python未安装
    pause
    exit /b 1
)

REM 安装依赖
echo [1/3] 安装依赖...
pip install pyinstaller Pillow -q

REM 转换图标
echo [2/3] 准备图标...
python -c "from PIL import Image; img = Image.open('docs/img/update.png'); img.save('docs/img/update.ico', format='ICO')" 2>nul

REM 清理
if exist build rmdir /s /q build 2>nul
if exist dist rmdir /s /q dist 2>nul
del /q *.spec 2>nul

REM 构建
echo [3/3] 构建中...
pyinstaller --name="JAR更新工具" --icon="docs/img/update.ico" --onefile --windowed --clean --noconfirm --add-data="templates;templates" --add-data="static;static" --add-data="tools;tools" --hidden-import=openpyxl --hidden-import=xlrd --hidden-import=pandas --hidden-import=flask --hidden-import=tkinter src/main.py

if exist "dist\JAR更新工具.exe" (
    echo.
    echo ✓ 构建成功！
    echo 文件位置: dist\JAR更新工具.exe
    echo.
    explorer dist
) else (
    echo.
    echo ✗ 构建失败
    pause
)




